<template>
  <div :class="['model-wrap', {mask: isShowMask}]" v-if="isShowModel">
    <div class="model">
      <div :class="['header', type, size]">
        {{ title }}
      </div>
      <div class="content">
        <slot></slot>
      </div>
      <div class="footer">
        <div class="btn-group">
          <button class="cancel" @click="onCancelFn($event)">取消</button>
          <button class="confirm" @click="onConfirm($event)">确认</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyModel',
  props: {
    title: {
      type: String,
      default: '这是一个标题'
    },
    type: {
      type: String,
      default: 'warn',
    },
    size: {
      type: String,
      default: 'middle'
    },
    isShowModel: {
      type: Boolean,
      default: true,
    },
    isShowMask: {
      type: Boolean,
      default: true,
    }
  },
  methods: {
    onCancelFn (e) {
      this.$emit('onCancel', e)
    },
    onConfirm (e) {
      this.$emit('onConfirm', e)
    }
  },
};
</script>

<style lang="scss">
body {
  margin: 0;
}
.model-wrap {
  position: fixed;
  width: 100%;
  height: 100%;
  &.mask {
    background-color: rgba($color: #000000, $alpha: 0.6);
    .model {
      background-color: #fff;
      box-shadow: 0 0 3px #ccc;
    }
  }
  .model {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 400px;
    overflow: hidden;
    border-radius: 10px;
    transform: translate(-50%, -50%);
    background-color: #eee;
    box-shadow: 3px 3px 2px #ccc;
    .header {
      height: 40px;
      text-align: center;
      line-height: 40px;
      &.min {
        font-size: 12px;
      }
      &.middle {
        font-size: 14px;
      }
      &.max {
        font-size: 16px;
      }
      &.primary {
        background-color: skyblue;
      }
      &.warn {
        background-color: orange;
      }
      &.danger {
        background-color: darkred;
      }
    }
    .content {
      box-sizing: border-box;
      padding: 10px;
      height: 100px;
      font-size: 14px;
    }
    .footer {
      padding: 10px;
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      .btn-group {
        button {
          border: 0;
          width: 60px;
          height: 30px;
          border-radius: 5px;
          font-size: 12px;
          cursor: pointer;
        }
        .cancel {
        }
        .confirm {
          background-color: orange;
        }
      }
    }
  }
}
</style>
